<?php

namespace App\Repositories\Role;

use  App\Repositories\Repository;
use App\Models\Role;
use Illuminate\Support\Facades\Request;

class RoleRepository extends Repository {

	public function __construct(Role $role) {
		$this->model = $role;
	}

	/**
	 * 更新一条记录
	 * @param array  $data
	 * @param        $id
	 * @param string $attribute
	 * @return mixed
	 */
	public function update(array $data, $id, $attribute = "id") {
		return $this->model->where($attribute, $id)->update([
			'display_name' => $data['display_name'],
			'description'  => $data['description'],
		]);
	}

	/**
	 * 分配权限
	 * @param array $roleId
	 * @param array $permissionIds
	 * @return array
	 */
	public function assignPermission($roleId,array $permissionIds) {
		$role = $this->find($roleId);
		return $role->perms()->sync($permissionIds);
	}
}
